<!DOCTYPE html>
<html height100 xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta th:replace="authority/dynamic/common/edit/head"/>
</head>

<body class="childrenBody" padding10>
<form class="layui-form layui-form-pane" lay-filter="form-dml" onsubmit="return false;">
    <input type="hidden" name="id" value="">
    <div class="layui-form-item">
        <label for="D_name" class="layui-form-label"><span class="x-red">*</span>标题</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="D_name" name="name" lay-verify="required"
                   placeholder="标题" autocomplete="off" value="">
        </div>
        <div class="my-notes">
            <div class="layui-elip layui-text content">
                用于浏览（格式：系统名称-功能作用）
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm6">
            <label for="D_dmlType" class="layui-form-label"><span class="x-red">*</span>DML类型</label>
            <div class="layui-input-block">
                <select name="dmlType" id="D_dmlType" type="text" lay-verify="required">
                    <option value="">--请选择--</option>
                    <option value="-1">anyWhere查询</option>
                    <option value="0">静态查询</option>
                    <option value="1">动态查询</option>
                    <option value="2">插入语句</option>
                    <option value="3">更新语句</option>
                    <option value="4">删除语句</option>
                    <option value="5">语句块</option>
                    <option value="6">过程</option>
                    <option value="7">函数</option>
                </select>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    anyWhere查询: 必须定义列<br>
                    静态查询 : 使用raw_dml来执行查询<br>
                    动态查询 : 必须定义列（暂未实现，确实需要动态语句请使用【anyWhere查询】）<br>
                    插入语句 : 插入语句<br>
                    更新语句 : 更新语句<br>
                    删除语句 : 删除语句<br>
                    语句块 : 执行语句块<br>
                    过程 : 执行存储过程<br>
                    函数 : 执行函数
                </div>
            </div>
        </div>
        <div class="layui-col-sm6">
            <label for="D_dmlType" class="layui-form-label"><span class="x-red">*</span>DML分组(分类)</label>
            <div class="layui-input-block">
                <select name="categoryId" id="D_categoryId" type="text" lay-verify="required">
                    <option value="">--请选择--</option>
                </select>
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    DML分组/分类 （系统：是只系统默认dml 不推荐私自操作）
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15 layui-form-item">
        <div class="layui-col-sm6">
            <label for="D_pageSize" class="layui-form-label">页面大小</label>
            <div class="layui-input-block">
                <input type="number" id="D_pageSize" name="pageSize" autocomplete="off" class="layui-input"
                       placeholder="页面大小" value="">
            </div>
        </div>
        <div class="layui-col-sm6">
            <label for="D_maxPageSize" class="layui-form-label">页面最大值</label>
            <div class="layui-input-block">
                <input type="number" id="D_maxPageSize" name="maxPageSize" autocomplete="off" class="layui-input"
                       placeholder="页面最大值" value="">
            </div>
            <div class="my-notes">
                <div class="layui-elip layui-text content">
                    分页信息最大值控制
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-form-item" pane>
        <label for="D_isValid" class="layui-form-label"><span class="x-red">*</span>是否有效</label>
        <div class="layui-input-block">
            <input type="checkbox" name="isValid" id="D_isValid" lay-skin="switch" checked lay-text="正常|无效">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label for="D_rawDml" class="layui-form-label"><span class="x-red">*</span>数据语句</label>
        <div class="layui-input-block">
            <pre style="height: 100px;width: 100%" id="D_rawDml" name="rawDml"></pre>
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" style="float: right" id="my-submit" lay-filter="submit" lay-submit>保存信息</button>
    </div>
</form>

<script th:replace="authority/dynamic/common/edit/footer"></script>
<script>
    var editor_rawdml = createAce("D_rawDml", "ace/mode/sql");
    layui.use(['form', 'lutil', 'initPage'], function () {
        var form = layui.form,
            lutil = layui.lutil,
            initPage = layui.initPage;
        initPage.render({successCallback: initPageSuccess})
            .addFunction(initCategoryIdOptions)
            .start();

        function initCategoryIdOptions(functionSuccess) {
            ajaxRequestByCsrf(content_path + 'authority/dic/recursion_list.do', {
                startIds: "F4BCAF1972974D29A5405022EEFFA37C"
            }, function (res) {
                for (var i = 0; i < res.data.length; i++) {
                    $("#D_categoryId").append('<option value="' + res.data[i]['id'] + '">' + res.data[i]['name'] + ' </option>');
                }
                form.render('select', 'form-dml');
            }, null, function (res) {
                functionSuccess();
            });
        }

        function initPageSuccess() {
            if ("[[${id}]]" !== '') {
                var loding = layer.load(2, {shade: [0.3, '#eee']});
                ajaxRequestByCsrf(content_path + 'authority/dml/detail/[[${id}]].do', {}, function (res) {
                    form.val("form-dml", $.extend(res.data, {isValid: res.data['isValid'] === 1}));
                    editor_rawdml.setValue(res.data['rawDml'] || '');
                }, null, function (res) {
                    layer.close(loding);
                });
            }
        }


        form.on('submit(submit)', function (formData) {
            var rawDml = editor_rawdml.getValue();
            if (!rawDml || rawDml === '' || $.trim(rawDml) === '')
                return lutil.error_alert("数据语句不能为空！！"), false;
            var loding = layer.load(2, {shade: [0.3, '#eee']});
            ajaxRequestByCsrf(content_path + 'authority/dml/save.do', $.extend(formData.field, {
                rawDml: rawDml,
                isValid: formData.field['isValid'] ? 1 : 0
            }), function (res) {
                lutil.success_msg(res.message);
                var index = window.name && parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            }, null, function (res) {
                layer.close(loding);
            });
            return false;
        });
    })
</script>
</body>
</html>